﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Imagin.Controls.Common"
    xmlns:Common="http://imagin.tech/imagin/common">
    <Common:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    <Common:StringToVisibilityConverter x:Key="StringToVisibilityConverter"/>

    <Style x:Key="{x:Type local:TextBoxExt}" TargetType="{x:Type local:TextBoxExt}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:TextBoxExt}">
                    <Border 
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}" 
                        BorderBrush="{TemplateBinding BorderBrush}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock 
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                Margin="{TemplateBinding Padding}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                Style="{TemplateBinding PlaceholderStyle}"
                                Text="{TemplateBinding Placeholder}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Visibility="{TemplateBinding Text, Converter={StaticResource StringToVisibilityConverter}, ConverterParameter=Inverted}"/>
                            <ScrollViewer 
                                x:Name="PART_ContentHost" 
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                Margin="{TemplateBinding Padding}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <Grid Grid.Column="1" Visibility="{TemplateBinding CanUserClear, Converter={StaticResource BooleanToVisibilityConverter}}">
                                <local:MaskedButton
                                    x:Name="PART_ClearButton"
                                    ImageColor="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
                                    Source="pack://application:,,,/Imagin.Controls.Common;component/Images/XRound.png"
                                    Margin="5,0"
                                    Visibility="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource StringToVisibilityConverter}}"/>
                            </Grid>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>